/* Description: 多线程测试
 * Author: zhouhui
 * Release Date: 2014-09-01
 * Modify log: 2014-09-03 
 */ 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

int sum(int a,int b)
{
    return a+b;
}


void * t1(void *arg)
{
    long *z=(long*)arg;
    printf("%ld,%ld\n",z[0],z[1]);

    long s = sum(z[0],z[1]);
    pthread_exit((void*)s);
}

int main(int argc, char **argv)
{
    int c=argc/2;
    pthread_t tid[c];
    long args[c][2];
    int i;
    for (i=1;i<=c;i++)
    {
        args[i-1][0] = atoi(argv[i*2-1]);
        args[i-1][1] = atoi(argv[i*2]);
    }

    int j;
    for(j=0; j<c; j++)
    {
        if (pthread_create(&(tid[j]),NULL,t1,args[j]) != 0)
        {
            perror("pthread_create");
            return 1;
        }
    }


    void *ret[c];
    int k;
    for (k=0; k<c; k++)
    {
        pthread_join(tid[k],&(ret[k]));
        printf("ret=%ld\n",(long)ret[k]);
    }

    return 0;
}

